package com.zzy.app.config;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;


public class ComponentScanTypeFilter implements TypeFilter {
    /**
     * @param metadataReader 当前正在扫描的类信息
     * @param metadataReaderFactory 其他任何类的信息工厂
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //当前类注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        //当前类信息 它的类型及接口实现等
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //当前类资源信息 它的类路径等
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("my filter print classname>>>" + className);

        if(className.contains("Test")){
            return true;
        }
        return false;
    }
}
